<?php

/**
 * XHTML_Html, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Html class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_I18n_Element.php";
include_once "XHTML_Head.php";
include_once "XHTML_Body.php";

/**
 * The XHTML_Html class is a handler for the html xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Html extends XHTML_I18n_Element {
    
    // xhtml atributes
    /**
     * Unique identifier for the id xhtml-html-tag.
     *
     * @var string
     */
    protected $id;
    
    // Component elements
    /**
     * Head of this html tag.
     *
     * @var XHTML_Head
     */
    protected $head;
    
    /**
     * Body of this html tag.
     *
     * @var XHTML_Body
     */
    protected $body;
    
    /**
     * Constructs a XHTML_Html object.
     *
     * @param XHTML_Head $head
     * @param XHTML_Body $body
     */
    function __construct(XHTML_Head $head, XHTML_Body $body)
    {
        $this->head = $head;
        $this->body = $body;
    }
    
    /**
     * Sets the unique identifier.
     *
     * @param string $id
     */
    function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * Gets the unique identifier.
     *
     * @return string
     */
    function getId()
    {
        return $this->id;
    }
    
    /**
     * Sets the head element of this html tag.
     *
     * @param XHTML_Head $head
     */
    function setHead(XHTML_Head $head)
    {
        $this->head = $head;
    }
    
    /**
     * Gets the head element that has been set for this tag.
     *
     * @return XHTML_Body
     */
    function getHead()
    {
        return $this->head;
    }
    
    /**
     * Sets the body element of this tag.
     *
     * @param XHTML_Body $body
     */
    function setBody(XHTML_Body $body)
    {
        $this->body = $body;
    }
    
    /**
     * Gets the body element that has been set for this tag.
     *
     * @return XHTML_Body
     */
    function getBody()
    {
        return $this->body;
    }
    
    // Overriding the toString method for a proper implementation.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
    	$auxString = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
        \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
        $auxString = $auxString."<html".parent::toString();
        
        /*
         * Additions of the html own attributes to the return string.
         */
        if (isset($this->id)) {
            $auxString = $auxString."id=\"".$this->id."\" ";
        }
        
        // DO NOT DELETE THE FOLLOWING LINE.
        // xmlns is a fixed attribute.
        $auxString = $auxString."xmlns=\"http://www.w3.org/1999/xhtml\" >\n";
        
        /*
         * Additions of the inner elements of the html element to the return 
         * string.
         */
        $auxString = $auxString.$this->head->toString();
        $auxString = $auxString.$this->body->toString();
        
        $auxString = $auxString."</html>\n";
        
        return $auxString;
    }
    
}

?>